import axios from "axios";

const state = {};

const mutations = {
  setState(state, payload) {
    Object.keys(payload).forEach(function (key) {
      state[key] = payload[key];
    });
  },
  exportState(state) {
    window.console.log("exportState", state);
  },
};

const actions = {
  // loadState(context) {
  //   axios
  //     .get("./data/statics.json")
  //     .then((res) => {
  //       context.commit("setState", res.data);
  //     })
  //     .catch((err) => {
  //       window.console.log(err);
  //     });
  // },
  loadParams({ commit, rootState }) {
    let params = ["clientOffice", "rank", "level", "interest", "recordLevel", "clientRank", "position", "rectifyAttributes"];
    let user = rootState.login.userbase;
    axios
      .post("./api/load_params/", { user, params })
      .then((res) => {
        if (res.data.status == 0) {
          commit("setState", res.data.params);
        } else {
          window.console.log(res);
        }
      })
      .catch((err) => {
        window.console.log(err);
      });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};